c= input()
 
if len(str(c)) != 4:
    print(0)
else:
    m = False
    for length in range(4, 0, -1):
        if m:
            break
        for i in range(4 - length + 1):
            k = int(str(c)[i:i+length])
            if k < 2:
                continue
            for j in range(2, int(k**0.5) + 1):
                if k % j == 0:
                    break
            else:
                print(k)
                m = True
                break
    if not m:
        print(0)
